PREFIX ?= /usr
BINDIR ?= $(PREFIX)/bin
SBINDIR ?= $(PREFIX)/sbin
DATADIR ?= $(PREFIX)/share
SYSCONFDIR ?= /etc
UNITDIR ?= /lib/systemd/system

# TODO: make a custom location with a separate web server
CGI_DIR ?= /var/www/cgi-bin

install:
	# TODO: make a custom location with separate web server
	mkdir -p --mode=0755 $(DESTDIR)$(CGI_DIR)
	install -m0755 webserver/doskast-trigger-connect.cgi $(DESTDIR)$(CGI_DIR)

	mkdir -p --mode=0755 $(DESTDIR)$(UNITDIR)
	install -m0644 xpra-shadow/doskast-xpra-shadow.socket $(DESTDIR)$(UNITDIR)
	install -m0644 xpra-shadow/doskast-xpra-shadow.service $(DESTDIR)$(UNITDIR)

	mkdir -p --mode=0755 $(DESTDIR)/etc/systemd/system/doskast-xpra-shadow.service.d
	install -m0644 xpra-shadow/xpra-shadow-firewall.conf $(DESTDIR)/etc/systemd/system/doskast-xpra-shadow.service.d

	mkdir -p --mode=0755 $(DESTDIR)$(BINDIR)
	mkdir -p --mode=0755 $(DESTDIR)$(SBINDIR)
	install -m0755 server-watcher/doskast-server-watcher.sh $(DESTDIR)$(BINDIR)/doskast-server-watcher
	install -m0755 student-config/doskast-student-config.sh $(DESTDIR)$(SBINDIR)/doskast-student-config
	echo -e '#!/bin/sh\npkexec $(SBINDIR)/doskast-student-config "$$@"' > $(DESTDIR)$(BINDIR)/doskast-student-config
	chmod 0755 $(DESTDIR)$(BINDIR)/doskast-student-config
	install -m0755 xpra-shadow/doskast-xpra-shadow.sh $(DESTDIR)$(BINDIR)/doskast-xpra-shadow
	install -m0755 student-connect/doskast-student-connect.sh $(DESTDIR)$(BINDIR)/doskast-student-connect

	mkdir -p --mode=0755 $(DESTDIR)$(SYSCONFDIR)/xdg/autostart
	install -m0644 server-watcher/doskast-server-watcher.desktop $(DESTDIR)$(SYSCONFDIR)/xdg/autostart
	install -m0644 xpra-shadow/doskast-xpra-shadow.desktop $(DESTDIR)$(SYSCONFDIR)/xdg/autostart

	mkdir -p --mode=0755 $(DESTDIR)$(DATADIR)/polkit-1/actions
	install -m0644 student-config/ru.mos.doskast-student-config.policy $(DESTDIR)$(DATADIR)/polkit-1/actions

	mkdir -p --mode=0755 $(DESTDIR)$(DATADIR)/applications
	install -m0644 student-config/doskast-student-config.desktop $(DESTDIR)$(DATADIR)/applications
	install -m0644 student-connect/doskast-student-connect.desktop $(DESTDIR)$(DATADIR)/applications
